Skip to content

Conversation

@daniel-lxs
Copy link
Member

@daniel-lxs daniel-lxs commented Dec 8, 2025

Summary

Follow-up to PR #9927 - same fix applied to the xAI provider.

When using native tool calling, if an API returns finish_reason: "tool_calls" but delays or fails to send the [DONE] stream termination signal, the stream would hang indefinitely waiting for tool calls to be finalized.

Fix

This PR:

  • Imports NativeToolCallParser in xai.ts
  • Captures finishReason from chunk.choices[0]?.finish_reason
  • Processes finish_reason during streaming to immediately emit tool_call_end events
  • Ensures tool calls are finalized as soon as finish_reason is received, without waiting for [DONE]

Testing

  • Added test for xai.ts to verify tool_call_end events are emitted when finish_reason: "tool_calls" is received
  • All 18 xAI tests pass
  • All 4553 tests pass in full test suite

Important

Fixes stream hanging issue in xai.ts by processing finish_reason to emit tool_call_end events immediately.

  • Behavior:
    • In xai.ts, captures finishReason from chunk.choices[0]?.finish_reason and processes it to emit tool_call_end events immediately.
    • Ensures tool calls are finalized without waiting for [DONE] signal.
  • Testing:
    • Adds test in xai.spec.ts to verify tool_call_end events are emitted when finish_reason: "tool_calls" is received.
    • Confirms all 18 xAI tests and 4553 full test suite tests pass.

This description was created by Ellipsis for 6c2f4bb. You can customize this summary. It will automatically update as commits are pushed.

Same fix as roo.ts and openrouter.ts - process finish_reason during
streaming to emit tool_call_end events immediately, ensuring tool calls
are finalized without waiting for [DONE] stream termination signal.
@daniel-lxs daniel-lxs requested review from cte, jr and mrubens as code owners December 8, 2025 22:54
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. bug Something isn't working labels Dec 8, 2025
@roomote
Copy link
Contributor

roomote bot commented Dec 8, 2025

Rooviewer Clock   See task on Roo Cloud

Review complete. No issues found.

The implementation correctly adds finish_reason processing to the xAI provider, following the same pattern established in roo.ts and openrouter.ts. The test adequately covers the expected behavior.

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Dec 8, 2025
@hannesrudolph hannesrudolph moved this from Triage to Issue [Needs Approval] in Roo Code Roadmap Dec 8, 2025
@hannesrudolph hannesrudolph added Issue - Needs Approval Ready to move forward, but waiting on maintainer or team sign-off. and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels Dec 8, 2025
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Dec 9, 2025
@mrubens mrubens merged commit 2efebf5 into main Dec 9, 2025
27 checks passed
@mrubens mrubens deleted the fix/xai-process-finish-reason-for-tool-calls branch December 9, 2025 02:03
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Dec 9, 2025
@github-project-automation github-project-automation bot moved this from Issue [Needs Approval] to Done in Roo Code Roadmap Dec 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Issue - Needs Approval Ready to move forward, but waiting on maintainer or team sign-off. lgtm This PR has been approved by a maintainer size:M This PR changes 30-99 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants